require(['grid', 'topBar'], function () {
	var $vehicleTypeTab = $("#vehicleTypeTab");
	//顶层搜索
	$('#top').topBar({
        right:[{
        	 text: '导出',
        	   type: 'export-btn',//固定写法
        	   //authority: '',//以后按钮权限需要用到的
        	   item: [
        	       {
        	           text: 'Excel导出',
        	           click: function () {//点击事件
        	        	   exportFile('Excel');
        	           }
        	       },
        	       {
        	           text: 'PDF导出',
        	           click: function () {
        	        	   exportFile('Pdf');
        	           }
        	       }
        	   ]
        },
        {
            text: '查询',
            type: 'btn',
            click: function () {
            	searchVehicleTypeTab();
            }
        }
        ]
    });
	
	function exportFile(suffix) {
        var url = "/vehicleManage/getVehicleCount" + suffix + ".htm";
        $.exportFile(url, null);
    }
	
	$vehicleTypeTab.grid({
		multiselect: false,
        url: "/vehicleManage/getVehicleTypeCount.htm",
        height:$(window).height()-80,
        colModel: [
			{name: "organName", index: "organName", sortable:false,align: "left", label:"组织名称", fixed:true},
			{name: "lineName", index: "lineName", sortable:false, label:"线路名称", align: "left", fixed:true},
			{name: "carNum", index: "carNum", sortable:false,label:"车辆数量", align: "right", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carTotal1Num", index: "carTotal1Num", sortable:false, label:"小计", align: "right", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType1Num", index: "carType1Num", sortable:false,align: "right", label:"柴油车", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType2Num", index: "carType2Num", sortable:false,align: "right", label:"汽油车", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carTotal2Num", index: "carTotal2Num", sortable:false,align: "right", label:"小计", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType3Num", index: "carType3Num", sortable:false,align: "right", label:"混合动力车", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType4Num", index: "carType4Num", sortable:false,align: "right", label:"纯电动车", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType5Num", index: "carType5Num", sortable:false,align: "right", label:"CNG", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'},
			{name: "carType6Num", index: "carType6Num", sortable:false,align: "right", label:"LNG", fixed:true, summaryType: "sum", summaryTpl: '小计: {0}'}
        ],
        userDataOnFooter: true,
		groupHeader:true,
		autoScroll: true,
		shrinkToFit:false,
		groupingView: {
			groupField: ["lineName"],
			groupSummary: [false],
			groupText: ['{0}'],
			groupColumnShow: [true], // 是否显示分组的列
			groupSummaryPos: ['footer']
		}
	});
	
	var groupHeaders = [];
	groupHeaders.push({
		startColumnName : "carTotal1Num" ,
		numberOfColumns : 3,
		titleText : "<b>传统车</b>"
	});
	groupHeaders.push({
		startColumnName : "carTotal2Num" ,
		numberOfColumns : 5,
		titleText : "<b>新能源</b>"
	});
	//添加标题组
	$vehicleTypeTab.grid( 'setGroupHeaders' , {
		useColSpanStyle :  true ,
		groupHeaders : groupHeaders
	}).jqGrid('setFrozenColumns');
	
	/**
	 * 查询车辆类型
	 */
	function searchVehicleTypeTab(){
		$vehicleTypeTab.grid('setGridParam', {
	         datatype: "JSON",
	         page: 1
	    }).trigger("reloadGrid");
	}
});